package cn.kongwg.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @author kongwg
 * @create 2021-05-01 20:02
 */

class MyThread implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("--------------call");
        TimeUnit.SECONDS.sleep(4);
        return 1024;
    }
}

public class CallableDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask(new MyThread());
        new Thread(futureTask,"a").start();
        new Thread(futureTask,"b").start();
        System.out.println("完成");
        System.out.println("futureTask = " + futureTask.get());
    }
}
